package com.reyco1.medusa.display.graphics
{
	import com.reyco1.medusa.display.SmartSprite;
	import com.reyco1.medusa.util.MathUtil;
	
	import flash.display.GradientType;
	import flash.geom.Matrix;

	public class Box
	{
		public static function draw(x:Number, y:Number, width:Number, height:Number, color:uint, 
									alpha:Number = 1, lineObject:Object = null):SmartSprite
		{
			var s:SmartSprite = new SmartSprite();
			s.graphics.clear();
			s.graphics.beginFill(color, alpha);
			if(lineObject)
			{
				var thickness:Number = lineObject.thickness == undefined ? null : lineObject.thickness;
				var lineAlpha:Number = lineObject.alpha == undefined ? 1 : lineObject.alpha;
				var lineColor:Number = lineObject.color == undefined ? 0 : lineObject.color;
				s.graphics.lineStyle(thickness, lineColor, lineAlpha);
			}
			s.graphics.drawRect(x, y, width, height);
			s.graphics.endFill();
			return s;
		}
		
		public static function drawGradiant(x:Number, y:Number, width:Number, height:Number, colors:Array, 
											alphas:Array, ratios:Array, lineObject:Object = null):SmartSprite
		{
			var s:SmartSprite = new SmartSprite();
			s.graphics.clear();
			if(lineObject)
			{
				var thickness:Number = lineObject.thickness == undefined ? null : lineObject.thickness;
				var lineAlpha:Number = lineObject.alpha == undefined ? 1 : lineObject.alpha;
				var lineColor:Number = lineObject.color == undefined ? 0 : lineObject.color;
				s.graphics.lineStyle(thickness, lineColor, lineAlpha);
			}
			
			var type:String 	 = GradientType.LINEAR;
			var gradColor:Array  = colors;
			var gradAlphas:Array = alphas;
			var gradRatios:Array = ratios;
			var matrix:Matrix 	 = new Matrix();
			matrix.createGradientBox(width, height, MathUtil.toRadians(90));
			
			s.graphics.beginGradientFill(type, gradColor, gradAlphas, gradRatios, matrix);			
			s.graphics.drawRect(x, y, width, height);
			s.graphics.endFill();
			return s;
		}
	}
}